package cn.iocoder.springboot.lab23.springmvc.controller;

import cn.iocoder.springboot.lab23.springmvc.dto.UserAddDTO;
import cn.iocoder.springboot.lab23.springmvc.dto.UserUpdateDTO;
import cn.iocoder.springboot.lab23.springmvc.vo.UserVO;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/users2")
public class UserController2 {
    @GetMapping
    public List<UserVO> list() {
        List<UserVO> result = new ArrayList<>();
        result.add(new UserVO().setId(1).setUsername("yudaoyuanma"));
        result.add(new UserVO().setId(2).setUsername("woshiyutou"));
        result.add(new UserVO().setId(3).setUsername("chifanshuijiao"));
        return result;
    }

    @GetMapping("/get")
    public UserVO get(@RequestParam("id") Integer id) {
        return new UserVO().setId(id).setUsername(UUID.randomUUID().toString());
    }

    @PostMapping("/add")
    public Integer add(UserAddDTO addDTO) {
        System.out.println("addDTO = " + addDTO);
        Integer returnId = UUID.randomUUID().hashCode();
        return returnId;
    }

    @PostMapping("/update")
    public Boolean update(UserUpdateDTO updateDTO) {
        Boolean success = true;
        return success;
    }

    @PostMapping("delete")
    public Boolean delete(@RequestParam Integer id) {
        Boolean success = true;
        return success;
    }
}
